$(function (){
    $("#log").click(function (){
        let username = $("#usernameinput").val()
        let password = $("#passwordinput").val()
        $.ajax({
            type:"post",
            url:"http://127.0.0.1:9090/login",
            data:{username:username,password:password},
            success:function (res){
                result = eval(res)
                if(result.length==0){
                    alert("用户名或密码输入错误！")
                    return
                }
                sessionStorage.setItem("userid",result[0].id)
                sessionStorage.setItem("username",result[0].username)
                alert("登录成功！")
                window.location.href="chatroom.html"
            },
            error:function (err){
                alert("请求失败")
            },

        })
    })
})